package com.ithrima.activiti.day03.activiti;


import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.NativeProcessDefinitionQuery;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;

import java.util.List;

/**
 *  查询流程定义
 */
public class QueryProcessDefinition {


    public static void main(String[] args) {
        // 1. 得到processEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2. 创建RepoitoryService对象

        RepositoryService repositoryService = processEngine.getRepositoryService();
        //3  得到ProcessDefinitionQuery对象
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
        //4. 设置条件，并查询当前所有流程定义
        List<ProcessDefinition> myProcess = processDefinitionQuery.processDefinitionKey("myProcess_1").orderByProcessDefinitionVersion().desc().list();

        //5. 输出流程定义
        for (ProcessDefinition process : myProcess) {
            System.out.println("流程定义ID："+process.getId());
            System.out.println("流程定义名称："+process.getName());
            System.out.println("流程定义的Key："+process.getKey());
            System.out.println("流程定义的版本号："+process.getVersion());
            System.out.println("流程部署的ID:"+process.getDeploymentId());
        }
    }
}
